﻿<%@ WebHandler Language="VB" Class="Report" %>

Imports System
Imports System.Web

Public Class Report : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim SessionID As String = Request.QueryString("SessionID")
        Dim FilePath As String = System.Web.HttpContext.Current.Server.MapPath("~/Download/OWC/" & SessionID & "/Report.xls")
        context.Response.ContentType = "text/plain"
        If IO.File.Exists(FilePath) Then
            context.Response.Write(IO.File.ReadAllText(FilePath))
            'If IO.Directory.Exists(System.IO.Path.GetDirectoryName(FilePath)) Then
            '    IO.Directory.Delete(System.IO.Path.GetDirectoryName(FilePath), True)
            'End If
            Dim newFilePath As String = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Empty.xml")
            IO.File.Copy(newFilePath, FilePath, True)
        End If
        context.Response.End()
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class